Component({
  mixins: [],
  data: {
    panelVisible: false,
    money: 3321,
    taskList: [
      {
        category: '新人任务',
        tasks: [
          {
            title: '收藏人人租机小程序',
            reward: 30,
            status: 0,
            icon: '../../../../assets/image/task1.png'
          },
          {
            title: '进行实名认证',
            reward: 50,
            status: 0,
            icon: '../../../../assets/image/task2.png'
          }
        ]
      },
      {
        category: '每天逛逛',
        tasks: [
          {
            title: '逛一逛活动页',
            reward: 10,
            status: 0,
            icon: '../../../../assets/image/task4.png'
          },
          {
            title: '逛一逛首页',
            reward: 10,
            status: 0,
            icon: '../../../../assets/image/task4.png'
          },
          {
            title: '逛一逛生活号首页',
            reward: 10,
            status: 0,
            icon: '../../../../assets/image/task4.png'
          },
          {
            title: '去分享',
            reward: 5,
            status: 0,
            icon: '../../../../assets/image/task3.png'
          }
        ]
      }
    ]
  },
  ref() {
    return {
      show: () => this.show()
    };
  },
  methods: {
    closePanel() {
      this.setData({
        panelVisible: false
      })
    },
    getReward(e) {
      const { task } = e.target.dataset
      if (task.status === 1) return
      this.setData({
        money: this.data.money + task.reward,
        taskList: this.data.taskList.map(taskGroup => {
          return {
            ...taskGroup,
            tasks: taskGroup.tasks.map(item => {
              if (item.title === task.title) {
                item.status = 1
              }
              return item
            })
          }
        })
      })
      // toastRef.value?.showToast({
      //   message: `恭喜获得${task.reward}个租币`,
      //   description: '任务完成',
      //   money: task.reward
      // })
      task.status = 1
    },
    show() {
      this.setData({
        panelVisible: true
      })
    }
  },
});
